<?php


namespace App\Admin\Extensions;

use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid\Displayers\AbstractDisplayer;

class MyQrcode extends AbstractDisplayer
{
    protected function addScript()
    {
        $script = <<<'SCRIPT'
$('.grid-column-qrcode').popover({
    html: true,
    container: 'body',
    trigger: 'focus'
});
SCRIPT;
        Admin::script($script);
    }

    public function display($param = [], $formatter = null, $width = 150, $height = 150)
    {
        $this->addScript();
        
        $imgUrl = $this->getColumn()->getOriginal();
        $name = 'room'.time();
        $img = sprintf(
            "<img src='".$imgUrl."' style='height:%spx;width:%spx;'/>",
            $width,
            $height,
            $content = '',
            $height,
            $width
        );
        $src = sprintf(
            $imgUrl,
            $width,
            $height,
            $content,
            $height = '',
            $width
        );

//        $img = str_replace('"', '\'', $img);
//        dd($img, $src);
        return <<<HTML
<a href="{$imgUrl}" download='{$name}' target='_blank' class='text-muted'>
    <i class="fa fa-download"></i>
</a>
<a href="javascript:void(0);" class="grid-column-qrcode text-muted" data-content="{$img}" data-toggle='popover' tabindex='0'>
<i class="fa fa-qrcode"></i></a>
HTML;
    }
}
